package com.huazi.www.doctor.doctorc.service.impl;

import com.huazi.www.doctor.doctorc.dao.MedicineDao;
import com.huazi.www.doctor.doctorc.dao.impl.MedicineDaoImpl;
import com.huazi.www.doctor.doctorc.entity.DrugEntity;
import com.huazi.www.doctor.doctorc.entity.MedicineEntity;
import com.huazi.www.doctor.doctorc.service.MedicineService;
import com.huazi.www.doctor.doctorc.util.Page;

import java.util.List;

public class MedicineServiceimpl implements MedicineService {

    MedicineDao dao = new MedicineDaoImpl();

    /*
     *分页查询给Page类对象赋值
     * @param currPageNo  当前下标
     * @return  返回Page<MedicineEntity>类型
     */
    @Override
    public Page<MedicineEntity> MedicinePaging(int docid, String userName, Integer currPageNo) {
        //new对象
        Page<MedicineEntity> page = new Page<>();
        //插入当前页数
        page.setCurrPageNo(currPageNo);
        //插入每页显示
        page.setPageSize(6);
        //得到当前页数算出起始下标
        int start = (currPageNo - 1) * page.getPageSize();

        //得到总记录数
        int count = dao.TotalPageCountSelect(docid, userName);
        //插入总记录数
        page.setTotalPageCount(count);
        //得到当前显示的list集合 插入page
        List<MedicineEntity> list = dao.MedicineRecordSelect(docid, userName, start, page.getPageSize());
        page.setList(list);
        return page;
    }

    /**
     * 查询旧密码是否成功！
     *
     * @param doctorid  医生id
     * @param doctorpwd 医生密码
     * @return
     */
    @Override
    public boolean pwdSelectOK(String doctorid, String doctorpwd, String doctorpwdxin, String doctorPwdOk_pwd) {
        int count = dao.pwdSelectOK(doctorid, doctorpwd);
        int updatecount = 0;
        if (count > 0) {
            if (doctorpwdxin == doctorPwdOk_pwd) {
                updatecount = dao.updatePwd(doctorpwdxin, doctorid);
            }
        }
        if (updatecount > 0) {
            return true;
        }
        return false;
    }

    /**
     * 删除方法
     */
    public void delete(int id) {
        dao.delete(id);
    }

    /**
     * 修改方法
     */
    public void update(MedicineEntity m) {
        dao.update(m);
    }

    /**
     * 得到所有药品的记录
     */
    public List<DrugEntity> list() {
        return dao.list();
    }
}
